export const parseJSON = (json, defaultValue) => {
  try {
    if (json == null) return defaultValue;
    return JSON.parse(json);
  } catch (e) {
    console.log("[ERROR] parseJSON", e);
    return defaultValue;
  }
};

/**
 * 生成唯一id
 */
export function guid(prefix = "") {
  return (
    prefix +
    "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
      const r = (Math.random() * 16) | 0,
        v = c == "x" ? r : (r & 0x3) | 0x8;
      return v.toString(16);
    })
  );
}

/** 表格序号 */
export function indexMethod(index, current, pageSize) {
  return index + 1 + (current - 1) * pageSize;
}
